<!--  -->
<template>
  <view class="page">
    <cu-custom
      :needBack="true"
      bgColor="bgNormal"
      topTitle="组织申请审核"
      titleClass="commTitleWhite"
      backIconColor="#fff"
    ></cu-custom>
    <view class="content">
			<view class="form">
				<view class="item">
					<view class="item-title">组织名称</view>
					<view class="item-content">{{ form.createUserName || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">社会组织类型</view>
					<view class="item-content">{{ form.socialOrganizationType || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">申请级别</view>
					<view class="item-content">{{ form.declarationLevel || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">业务主管单位</view>
					<view class="item-content">{{ unitName || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">法定代表人</view>
					<view class="item-content">{{ form.legalPerson || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">法定代表人电话</view>
					<view class="item-content">{{ form.phone || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">申请时间</view>
					<view class="item-content">{{ form.createTime || '--' }}</view>
				</view>
				<view class="item">
					<view class="item-title">社会组织章程</view>
					<view @click="doPreviewImage(form.url)" class="item-content"><image class="img" :src="form.url"></image></view>
				</view>
			</view>
			<view v-if="form.status != 3" class="footer">
				<u-button @click="confirm(3)" class="btn" type="primary" plain>审核通过</u-button>
				<u-button @click="confirm(2)" class="btn" type="error" plain>审核不通过</u-button>
			</view>
    </view>
  </view>
</template>

<script>
import { getOrgApply, checkUpOrgApply } from "@/api/expert"
export default {
  data() {
    return {
			applyId: '',
			unitName: '',
			form: {}
    }
  },
  onLoad(options) {
		this.applyId = options.applyId || ''
		this.unitName = decodeURIComponent(options.unitName || '')
		this.loadOrgApply()
  },
  methods: {
		// 保存
		confirm(status) {
			let msg = '是否确认审核通过？';
			if (status == 2) {
				msg = '是否确认审核不通过？';
			}
			uni.showModal({
			  title: "提示",
			  content: msg,
			  confirmText: "确定",
			  success: (res) => {
			    if (res.confirm) {
						let params = {
							...this.form,
							status
						}
						console.log('params', params);
						checkUpOrgApply(params).then(res => {
							if (res.code == 200) {
								this.showToast('审核成功')
								setTimeout(() => {
									uni.navigateBack()
								}, 1500)
							}
						})
			    } else if (res.cancel) {
			      console.log("用户点击取消");
			    }
			  },
			});
		},
		showToast(title) {
			uni.showToast({
			  title,
			  icon: "none"
			})
		},
		doPreviewImage(fileUrl) {
			let arr = [fileUrl]
			uni.previewImage({
				current: 0,
				urls: arr,
				indicator: "number",  
				loop: true 
			});
		},
		// 获取详情
		loadOrgApply() {
			let params = {
				id: this.applyId
			}
			getOrgApply(params).then(res => {
				if (res.code == 200) {
					res.data.url = this.getFileUrl(res.data)
					this.form = res.data || {}
					console.log('form', this.form);
					console.log('form', this.form.declarationLevel);
				}
			})
		},
		getFileUrl(item) {
			if (!item.url) {
				return ''
			}

			let url = item.url 
			if (item.bucketName) {
				url = 'https://wxdengji.oss-cn-hangzhou.aliyuncs.com' + url
			} else if (item.url.indexOf('https://pinggu.mkcom.cn/grade-evaluation-file/') == -1) {
				url = 'https://pinggu.mkcom.cn/grade-evaluation-file/' + item.url
			}
			return url
		},
  }
};
</script>
<style lang="scss" scoped>
.page {
	width: 100%;
	height: 100vh;
	display: flex;
	flex-direction: column;
}
.content {
	flex: 1;
	width: 100%;
  font-size: 28rpx;
  color: #999;
	background: #fff;
	position: relative;
	display: flex;
	flex-direction: column;
}
.footer {
	padding: 30rpx;
	border-top: 1px solid #efefef;
	display: flex;
	justify-content: space-between;
	.btn {
		width: 48%;
	}
}
.form {
	flex: 1;
	padding: 25rpx;
	width: 100%;
	box-sizing: border-box;
	overflow: auto;
	.red {
		color: red;
		padding-right: 5rpx;
	}
	.item {
		width: 100%;
		margin-bottom: 25rpx;
		padding: 0 10rpx 20rpx;
		border-bottom: 1px solid #efefef;
		display: flex;
		.item-title {
			width: 225rpx;
			color: #000;
		}
		.item-content {
			flex: 1;
			overflow: hidden;
			word-break: break-all;
		}
		.img {
			width: 100%;
		}
	}
	.item:last-child {
		border-bottom: none;
	}
}
</style>
